﻿using System;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

/// <summary>
/// Summary description for FormContract
/// </summary>
/// 

namespace ToolBoxPro
{
    public class FormContract
    {
        public FormContract()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public const string USER = "USER";
        public const string USER_GROUP = "GROUP";

        public const string AGENT_GROUP_ID = "AGENT_GROUP_ID";
        public const string AGENT = "AGENT";

        public const string CONTRACTOR_ID = "CONTRACTOR_ID";

        public const string GREETING_NAME = "GRAEETING_NAME";
        public const int THUMB_NAIL_SIZE_X = 50;
        public const int THUMB_NAIL_SIZE_Y = 50;

        public const string HIDDENT_PROPERTY_ID = "hidden_property_id";

        public const string VENDOR_STA_DIC = "VENDOR_STATUS_DICTIONARY";


        public static string GetDateLabel(DateTime? _date)
        {
            if (_date != null && _date.HasValue)
                return String.Format("{0:dd/MM/yyyy}", _date);
            return "";
        }

        public static int? FindKey(IDictionary<int, string> lookup,string value)
        {
            foreach (var pair in lookup)
            {
                if (pair.Value.ToLower() == value.ToLower())
                    return pair.Key;
            }
            return null;
        }
    }

    public class InsertDefault
    {
        public static Object process(object _field, object _value)
        {
            switch (TypeName(_field))
            {
                case "System.String":
                    if (_value == null || _field == "")
                        return _value;
                    break;
                case "System.Boolean":
                    if (_field == null)
                        return _value;
                    break;
                default:
                    return _value;
                    break;
            }

            return null;
        }

        static string TypeName<T>(T obj)
        {
            return typeof(T).Name.ToLower();
        }

        static string TypeName(object obj)
        {
            if (obj != null) { return obj.GetType().Name; }
            else { return null; }
        }

    }
}